import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { PmTeamProjectVO, PmTeamProjectQuery, PmTeamProjectForm } from './types'

/**
 * 查询团队项目关联列表
 * @param query
 * @returns {*}
 */
export const listTeamProject = (query?: PmTeamProjectQuery): AxiosPromise<PmTeamProjectVO[]> => {
  return request({
    url: '/pm/team-project/list',
    method: 'get',
    params: query
  })
}

/**
 * 查询团队项目关联详细
 * @param id
 */
export const getTeamProject = (id: string | number): AxiosPromise<PmTeamProjectVO> => {
  return request({
    url: '/pm/team-project/' + id,
    method: 'get'
  })
}

/**
 * 新增团队项目关联
 * @param data
 */
export const addTeamProject = (data: PmTeamProjectForm) => {
  return request({
    url: '/pm/team-project',
    method: 'post',
    data: data
  })
}

/**
 * 修改团队项目关联
 * @param data
 */
export const updateTeamProject = (data: PmTeamProjectForm) => {
  return request({
    url: '/pm/team-project',
    method: 'put',
    data: data
  })
}

/**
 * 删除团队项目关联
 * @param id
 */
export const delTeamProject = (id: string | number | Array<string | number>) => {
  return request({
    url: '/pm/team-project/' + id,
    method: 'delete'
  })
}

/**
 * 查询团队参与的项目列表
 * @param teamId
 */
export const getTeamProjects = (teamId: string | number): AxiosPromise<PmTeamProjectVO[]> => {
  return request({
    url: '/pm/team-project/team/' + teamId + '/projects',
    method: 'get'
  })
}

/**
 * 查询项目参与的团队列表
 * @param projectId
 */
export const getProjectTeams = (projectId: string | number): AxiosPromise<PmTeamProjectVO[]> => {
  return request({
    url: '/pm/team-project/project/' + projectId + '/teams',
    method: 'get'
  })
}

/**
 * 关联团队到项目
 * @param teamId
 * @param projectId
 * @param isPrimary
 */
export const associateTeamToProject = (teamId: string | number, projectId: string | number, isPrimary: boolean = false) => {
  return request({
    url: '/pm/team-project/associate',
    method: 'post',
    params: { teamId, projectId, isPrimary }
  })
}

/**
 * 取消团队与项目的关联
 * @param teamId
 * @param projectId
 */
export const disassociateTeamFromProject = (teamId: string | number, projectId: string | number) => {
  return request({
    url: '/pm/team-project/disassociate',
    method: 'post',
    params: { teamId, projectId }
  })
}

/**
 * 批量添加团队成员到项目
 * @param teamId
 * @param projectId
 */
export const addTeamMembersToProject = (teamId: string | number, projectId: string | number) => {
  return request({
    url: '/pm/team-project/add-members',
    method: 'post',
    params: { teamId, projectId }
  })
}

/**
 * 从项目移除团队成员
 * @param teamId
 * @param projectId
 */
export const removeTeamMembersFromProject = (teamId: string | number, projectId: string | number) => {
  return request({
    url: '/pm/team-project/remove-members',
    method: 'post',
    params: { teamId, projectId }
  })
}
